//
//  HongbaoDViewController.m
//  SelfDriving
//
//  Created by apple on 16/2/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HongbaoDViewController.h"
#import "BusinessService+User.h"
#import "SVProgressHUD.h"
#import "LoginResponseModel.h"
#import "XhwMSCtrl.h"
@interface HongbaoDViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *head_img;
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *qiang_money;
@property (weak, nonatomic) IBOutlet UILabel *titlelable;

@end

@implementation HongbaoDViewController
{
    NSMutableArray *data;
    LoginResponseModel *user;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _head_img.layer.cornerRadius = _head_img.frame.size.width/2;
    _head_img.clipsToBounds = YES;
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[[AppDelegate shareDelegate].hbdic objectForKey:@"id"] forKey:@"hongbao_id"];
    [[BusinessService shareInstance]hongbao_record:dic
                                           success:^(id result) {
                                              user  = result;
                                               data = user.list;
                                               _name.text = user.nickname;
                                               _qiang_money.text = [NSString stringWithFormat:@"%@",user.qiang_money];
                                               _titlelable.text = user.title;
                                               [ValidateHelper setImage:user.headsmall img:_head_img istoux:YES];
                                               [_table reloadData];
                                           } failure:^(id result) {
                                               [SVProgressHUD showErrorWithStatus:result];
                                           }];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return data.count;
}
//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//    return user.tip;
//}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //xhw2018-3-15改
    UIView *view = [[UIView alloc] init];
    UILabel *tiplabel = [[UILabel alloc] init];
    tiplabel.text = user.tip;
    tiplabel.textColor = [UIColor grayColor];
    tiplabel.font = [UIFont systemFontOfSize:13];

    tiplabel.frame = CGRectMake(10, 0, SCRE_WIDTH - 10, 20);
    [view addSubview:tiplabel];
    return view;
//    UILabel *label = Label.str(user.tip).color(@"gray").fnt(@13);
//    Label.frame = XYWH(10.f,0.f,SCREEN_WIDTH-10.f,20);
//    return label;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    
    NSMutableDictionary *dic = [data objectAtIndex:indexPath.row];
    
    
    
    UIImageView *img= [[UIImageView alloc]initWithFrame:CGRectMake(10, 55/2-45/2, 45, 45)];
    img.image = [UIImage imageNamed:@"touxiang"];
    img.layer.cornerRadius = img.frame.size.width/2;
    img.clipsToBounds = YES;
    [ValidateHelper setImage:[dic objectForKey:@"headsmall"] img:img istoux:YES];
    [cell.contentView addSubview:img];
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(65, 10, 200, 30)];
    lable.text = [dic objectForKey:@"nickname"];
    lable.font = [UIFont systemFontOfSize:16];
    [cell.contentView addSubview:lable];

    UILabel *time = [[UILabel alloc]initWithFrame:CGRectMake(65, 30, 200, 30)];
    time.text = [ValidateHelper timeStringWith:[[dic objectForKey:@"createtime"] doubleValue] multiLine:NO];
    time.font = [UIFont systemFontOfSize:12];
    time.textColor = UIColorGray;
    [cell.contentView addSubview:time];
    
    
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@元",[dic objectForKey:@"money"]];
    cell.detailTextLabel.textColor = UIColorBlack;
    return cell;
}

- (IBAction)backAction:(id)sender {
//    [self dismissViewControllerAnimated:YES completion:nil];
    
    [self toRootViewController];//xhw2018-3-15加
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
